package com.mck.controller;

import com.mck.entity.CommonProblem;
import com.mck.entity.Result;
import com.mck.service.CommonProblemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/public/commonProblem")
@Slf4j
public class CommonProblemController {

    @Autowired
    private CommonProblemService commonProblemService;

    /**
     * 获取常见问题
     */
    @GetMapping
    public Result getCommonProblem() {
        log.info("获取常见问题");

        List<CommonProblem> commonProblemList = commonProblemService.getCommonProblem();
        return Result.success(commonProblemList);
    }

    /**
     * 添加常见问题
     */
    @PostMapping
    public Result addCommonProblem(@RequestBody CommonProblem commonProblem) {
        log.info("添加常见问题");

        commonProblemService.addCommonProblem(commonProblem);
        return Result.success();
    }

    /**
     * 修改常见问题
     */
    @PutMapping
    public Result updateCommonProblem(@RequestBody CommonProblem commonProblem) {
        log.info("修改常见问题");

        commonProblemService.updateCommonProblem(commonProblem);
        return Result.success();
    }

    /**
     * 删除常见问题
     */
    @DeleteMapping("/{id}")
    public Result deleteCommonProblem(@PathVariable Integer id) {
        log.info("删除常见问题");

        commonProblemService.deleteCommonProblem(id);
        return Result.success();
    }
}
